<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>套餐管理 - 管理后台</title>
    <link rel="stylesheet" href="/static/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<div class="layui-col-md12">
    <form class="layui-form " action="" method="get">
        <blockquote class="layui-elem-quote title">
            <div class="layui-inline layui-float-right">
                <a class="layui-btn layui-btn-sm layui-btn-normal addProduct_btn" href="javascript:void(0);">添加套餐</a>
            </div>
            <span class="layui-breadcrumb">
            <a href="javascript:void(0);">套餐管理</a>
            <a><cite>套餐列表</cite></a>
        </span>
            <div class="layui-inline">
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <input name="name" value="" class="layui-input" placeholder="请输入套餐名称"/>
                </div>
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">搜索</button>
            </div>
        </blockquote>
    </form>
    <table id="productList" lay-filter="productList" class="layui-table"></table>
    <script type="text/html" id="productListTBar">
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
    </script>
    <script type="text/html" id="productImage">
        <img src="/{{ d.image }}" style="height:30px;"/>
    </script>
</div>
<script src="/static/layui.js"></script>
<script>
    layui.use(['element', 'jquery', 'layer', 'table', 'form'], function () {
        var element = layui.element,
            layer = layui.layer,
            $ = layui.jquery,
            table = layui.table,
            form = layui.form;
        form.on('submit(demo1)', function (data) {
            table.reload('productListTable', {
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        layui.tableIns = table.render({
            elem: '#productList',
            url: '{:url("product/lists")}',
            cellMinWidth: 95,
            page: true,
            limit: 15,
            limits: [15, 20, 30, 50],
            id: "productListTable",
            cols: [[
                {field: 'product_id', title: 'ID', width: 80, align: "center"},
                {field: 'name', title: '名称', align: "center"},
                {field: 'image', templet: '#productImage', title: '图片', width: 200, align: "center"},
                {field: 'price', title: '价格', width: 100, align: "center"},
                {field: 'deposit', title: '定金', width: 100, align: "center"},
                {
                    field: 'type', title: '类型', width: 100, align: "center", templet: function (d) {
                        return d.type == 1 ? '套餐' : '服务';
                    }
                },
                {field: 'create_time', title: '添加时间', width: 200, align: "center"},
                {title: '操作', templet: '#productListTBar', fixed: 'right', width: 150, align: 'center'}
            ]]
        });
        $('.childrenBody').on('click', 'img', function () {
            var img = new Array;
            img.push({src: $(this).attr('src')});
            layer.photos({
                photos: {data: img},
                anim: 5
            });
        });
        $(".addProduct_btn").click(function () {
            var index = layui.layer.open({
                title: "添加套餐",
                type: 2,
                content: "{:url('product/addProduct')}",
                area: ['100%', '100%']
            });
        });

        table.on('tool(productList)', function (obj) {
            var layEvent = obj.event,
                data = obj.data;
            if (layEvent === 'edit') {
                var index = layui.layer.open({
                    title: "编辑套餐",
                    type: 2,
                    content: "{:url('product/editProduct')}?id=" + data.product_id,
                    area: ['100%', '100%']
                });
            } else if (layEvent === 'delete') {
                layer.open({
                    content: '确定删除该套餐么？删除后不可恢复',
                    btn: ['确定', '取消'],
                    yes: function () {
                        var index = layer.load(1);
                        $.get('{:url("product/deleteProduct")}?id=' + data.product_id, function (data) {
                            if (data.code == 0) {
                                layer.close(index);
                                layer.msg(data.msg, {
                                    time: 3000,
                                    icon: 1
                                }, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.close(index);
                                layer.msg(data.msg, {icon: 5, shift: 6});
                            }
                        });
                        return true;
                    },
                    btn2: function () {
                        return true;
                    }
                });
            }
        });
    });
</script>
</body>
</html>